using System;
using System.Collections.Generic;
using System.Text;
using System.Workflow.Runtime.Tracking;
using System.Workflow.ComponentModel;

namespace OpenComposite.EII.Simulation
{
	public class SimulationTrackingProfile : TrackingProfile
	{
		#region Initialization
		public SimulationTrackingProfile()
		{
			init();
		}
		private void init()
		{
			// activity tracking
			ActivityTrackingLocation loc = new ActivityTrackingLocation(typeof(Activity));
			
			loc.ExecutionStatusEvents.Add(ActivityExecutionStatus.Initialized);
			loc.ExecutionStatusEvents.Add(ActivityExecutionStatus.Executing);
			loc.ExecutionStatusEvents.Add(ActivityExecutionStatus.Canceling);
			loc.ExecutionStatusEvents.Add(ActivityExecutionStatus.Faulting);
			loc.ExecutionStatusEvents.Add(ActivityExecutionStatus.Compensating);
			loc.ExecutionStatusEvents.Add(ActivityExecutionStatus.Closed);

			loc.MatchDerivedTypes = true;

			ActivityTrackPoint atp = new ActivityTrackPoint();
			atp.MatchingLocations.Add(loc);

			// workflow tracking
			WorkflowTrackPoint wtp = new WorkflowTrackPoint();
			wtp.MatchingLocation = new WorkflowTrackingLocation();

			wtp.MatchingLocation.Events.Add(TrackingWorkflowEvent.Aborted);
			wtp.MatchingLocation.Events.Add(TrackingWorkflowEvent.Changed);
			wtp.MatchingLocation.Events.Add(TrackingWorkflowEvent.Completed);
			wtp.MatchingLocation.Events.Add(TrackingWorkflowEvent.Created);
			wtp.MatchingLocation.Events.Add(TrackingWorkflowEvent.Exception);
			wtp.MatchingLocation.Events.Add(TrackingWorkflowEvent.Idle);
			wtp.MatchingLocation.Events.Add(TrackingWorkflowEvent.Loaded);
			wtp.MatchingLocation.Events.Add(TrackingWorkflowEvent.Persisted);
			wtp.MatchingLocation.Events.Add(TrackingWorkflowEvent.Resumed);
			wtp.MatchingLocation.Events.Add(TrackingWorkflowEvent.Started);
			wtp.MatchingLocation.Events.Add(TrackingWorkflowEvent.Suspended);
			wtp.MatchingLocation.Events.Add(TrackingWorkflowEvent.Terminated);
			wtp.MatchingLocation.Events.Add(TrackingWorkflowEvent.Unloaded);

			// custom tracking
			UserTrackingLocation userloc = new UserTrackingLocation();

			userloc.ActivityType = typeof(Activity);
			userloc.MatchDerivedActivityTypes = true;
			userloc.ArgumentType = typeof(object);
			userloc.MatchDerivedArgumentTypes = true;


			UserTrackPoint utp = new UserTrackPoint();
			utp.MatchingLocations.Add(userloc);

			// bobject activity tracking


			ActivityTrackingLocation logicalActivityLocation = new ActivityTrackingLocation(typeof(OpenComposite.Workflow.ILogicalActivity));

			logicalActivityLocation.ExecutionStatusEvents.Add(ActivityExecutionStatus.Initialized);
			logicalActivityLocation.ExecutionStatusEvents.Add(ActivityExecutionStatus.Executing);
			logicalActivityLocation.ExecutionStatusEvents.Add(ActivityExecutionStatus.Canceling);
			logicalActivityLocation.ExecutionStatusEvents.Add(ActivityExecutionStatus.Faulting);
			logicalActivityLocation.ExecutionStatusEvents.Add(ActivityExecutionStatus.Compensating);
			logicalActivityLocation.ExecutionStatusEvents.Add(ActivityExecutionStatus.Closed);

			logicalActivityLocation.MatchDerivedTypes = true;
			ActivityTrackPoint logicalActivityPoint = new ActivityTrackPoint();
			logicalActivityPoint.MatchingLocations.Add(logicalActivityLocation);
			logicalActivityPoint.Extracts.Add(new ActivityDataTrackingExtract("ActivitiesClass"));
			logicalActivityPoint.Extracts.Add(new ActivityDataTrackingExtract("LogicalActivityId"));

			ActivityTrackingLocation notificationLocation = new ActivityTrackingLocation(typeof(OpenComposite.Workflow.NotificationActivity));

			notificationLocation.ExecutionStatusEvents.Add(ActivityExecutionStatus.Initialized);
			notificationLocation.ExecutionStatusEvents.Add(ActivityExecutionStatus.Executing);
			notificationLocation.ExecutionStatusEvents.Add(ActivityExecutionStatus.Canceling);
			notificationLocation.ExecutionStatusEvents.Add(ActivityExecutionStatus.Faulting);
			notificationLocation.ExecutionStatusEvents.Add(ActivityExecutionStatus.Compensating);
			notificationLocation.ExecutionStatusEvents.Add(ActivityExecutionStatus.Closed);

			notificationLocation.MatchDerivedTypes = true;
			ActivityTrackPoint notificationPoint = new ActivityTrackPoint();
			notificationPoint.MatchingLocations.Add(notificationLocation);
			notificationPoint.Extracts.Add(new ActivityDataTrackingExtract("SimulatedNotification"));

			//ActivityTrackingLocation codeLocation = new ActivityTrackingLocation(typeof(System.Workflow.Activities.CodeActivity));
			//codeLocation.ExecutionStatusEvents.Add(ActivityExecutionStatus.Initialized);
			//codeLocation.ExecutionStatusEvents.Add(ActivityExecutionStatus.Executing);
			//codeLocation.ExecutionStatusEvents.Add(ActivityExecutionStatus.Canceling);
			//codeLocation.ExecutionStatusEvents.Add(ActivityExecutionStatus.Faulting);
			//codeLocation.ExecutionStatusEvents.Add(ActivityExecutionStatus.Compensating);
			//codeLocation.ExecutionStatusEvents.Add(ActivityExecutionStatus.Closed);

			//ActivityTrackPoint codePoint = new ActivityTrackPoint();
			//codePoint.MatchingLocations.Add(codeLocation);
			//codePoint.Extracts.Add(new WorkflowDataTrackingExtract(""));

			// initialize this
			this.Version = new Version(1, 0, 0, 0);
			this.ActivityTrackPoints.Add(atp);
			this.ActivityTrackPoints.Add(logicalActivityPoint);
			this.ActivityTrackPoints.Add(notificationPoint);
			//this.ActivityTrackPoints.Add(codePoint);
			this.WorkflowTrackPoints.Add(wtp);
			this.UserTrackPoints.Add(utp);
		}
		#endregion
	}
}
